package resource

import (
	"fcs-api/src/api"
	"fcs-api/src/resource/resourcequota"

	"k8s.io/api/core/v1"
	"k8s.io/apimachinery/pkg/api/errors"
)

type UpdateUserSpec struct {
	UserId string `json:"userId" valid:"-"`
	Role   string `json:"role" valid:"-"`
}

type AddUserSpec struct {
	UserIds []string `json:"userIds" valid:"-"`
	Role    string   `json:"role" valid:"-"`
}

type UserPassword struct {
	UserName string `json:"username"`
	Password string `json:"password"`
}

type UserName struct {
	User string `json:"user"`
}

type UserAuthToken struct {
	RefreshExpiresIn int    `json:"refresh_expires_in"`
	Scope            string `json:"scope"`
	SessionState     string `json:"session_state"`
	RefreshToken     string `json:"refresh_token"`
	ExpiresIn        int    `json:"expires_in"`
	AccessToken      string `json:"access_token"`
	RequestId        string `json:"request_id"`
	TokenType        string `json:"token_type"`
}

type NamespaceCreateSpec struct {
	Name                  string                 `json:"name" valid:"matches(^[a-z0-9]([-a-z0-9]*[a-z0-9])?$)~编码格式应为（小写字母、数字组成，例：test001）, length(1|20)~编码长度不能超过20"`
	DisplayName           string                 `json:"displayName" valid:"matches(^[\u4e00-\u9fa5a-zA-Z0-9]([-\u4e00-\u9fa5a-zA-Z0-9]*[\u4e00-\u9fa5a-zA-Z0-9])?$)~名称格式应为（字母、数字、汉字组成，例：IOP测试）"`
	ResourceQuotaSpec     *ResourceQuotaSpec     `json:"resourceQuotaSpec" valid:"-"`
	LimitRangeSpec        *LimitRangeSpec        `json:"limitRangeSpec" valid:"-"`
	CephStorageConfigSpec *CephStorageConfigSpec `json:"cephStorageConfigSpec" valid:"-"`
	IsIsolate             bool                   `json:"isIsolate" valid:"-"`
	RoleBindingSpec       *RoleBindingSpec       `json:"roleBindingSpec" valid:"-"`
}

type NamespaceUpdateSpec struct {
	Name                  string                 `json:"name" valid:"matches(^[a-z0-9]([-a-z0-9]*[a-z0-9])?$)~编码格式应为（小写字母、数字组成，例：test001）, length(1|20)~编码长度不能超过20"`
	DisplayName           string                 `json:"displayName" valid:"matches(^[\u4e00-\u9fa5a-zA-Z0-9]([-\u4e00-\u9fa5a-zA-Z0-9]*[\u4e00-\u9fa5a-zA-Z0-9])?$)~名称格式应为（字母、数字、汉字组成，例：IOP测试）, optional"`
	ResourceQuotaSpec     *ResourceQuotaSpec     `json:"resourceQuotaSpec" valid:"-"`
	LimitRangeSpec        *LimitRangeSpec        `json:"limitRangeSpec" valid:"-"`
	CephStorageConfigSpec *CephStorageConfigSpec `json:"cephStorageConfigSpec" valid:"-"`
	IsIsolate             bool                   `json:"isIsolate" valid:"-"`
	RoleBindingSpec       *RoleBindingSpec       `json:"roleBindingSpec" valid:"-"`
}

type ResourceQuotaSpec struct {
	Cpu                    int64 `json:"cpu" valid:"-"`
	CpuLimits              int64 `json:"cpuLimits" valid:"-"`
	CpuRequests            int64 `json:"cpuRequests" valid:"-"`
	Memory                 int64 `json:"memory" valid:"-"`
	MemoryLimits           int64 `json:"memoryLimits" valid:"-"`
	MemoryRequests         int64 `json:"memoryRequests" valid:"-"`
	StorageRequest         int64 `json:"storageRequest" valid:"-"`
	PersistentVolumeClaims int64 `json:"persistentVolumeClaims" valid:"-"`
	Configmaps             int64 `json:"configmaps" valid:"-"`
	Pods                   int64 `json:"pods" valid:"-"`
	Replicationcontrollers int64 `json:"replicationcontrollers" valid:"-"`
	Services               int64 `json:"services" valid:"-"`
	Nodeports              int64 `json:"nodeports" valid:"-"`
	Secrets                int64 `json:"secrets" valid:"-"`
}

type LimitRangeSpec struct {
	PodLimitRangeSpec *PodLimitRangeSpec `json:"podLimitRangeSpec" valid:"-"`
	//pod和container用一个即可
	ContainerLimitRangeSpec             *ContainerLimitRangeSpec             `json:"containerLimitRangeSpec" valid:"-"`
	PersistentVolumeClaimLimitRangeSpec *PersistentVolumeClaimLimitRangeSpec `json:"persistentVolumeClaimLimitRangeSpec" valid:"-"`
}

type PodLimitRangeSpec struct {
	CpuMax    int64 `json:"cpuMax"`
	CpuMin    int64 `json:"cpuMin"`
	MemoryMax int64 `json:"memoryMax"`
	MemoryMin int64 `json:"memoryMin"`
}

type ContainerLimitRangeSpec struct {
	CpuMax               int64 `json:"cpuMax" valid:"-"`
	CpuMin               int64 `json:"cpuMin" valid:"-"`
	MemoryMax            int64 `json:"memoryMax" valid:"-"`
	MemoryMin            int64 `json:"memoryMin" valid:"-"`
	CpuDefault           int64 `json:"cpuDefault" valid:"-"`
	CpuDefaultRequest    int64 `json:"cpuDefaultRequest" valid:"-"`
	MemoryDefault        int64 `json:"memoryDefault" valid:"-"`
	MemoryDefaultRequest int64 `json:"memoryDefaultRequest" valid:"-"`
}

type PersistentVolumeClaimLimitRangeSpec struct {
	StorageMin            int64 `json:"storageMin" valid:"-"`
	StorageMax            int64 `json:"storageMax" valid:"-"`
	StorageDefault        int64 `json:"storageDefault" valid:"-"`
	StorageDefaultRequest int64 `json:"storageDefaultRequest" valid:"-"`
}

type CephStorageConfigSpec struct {
	Name []string `json:"name" valid:"-"`
}

type RoleBindingSpec struct {
	Name string `json:"name" valid:"-"`
}

// NamespaceList contains a list of namespaces in the cluster.
type NamespaceList struct {
	ListMeta api.ListMeta `json:"listMeta"`

	// Unordered list of Namespaces.
	Namespaces []Namespace `json:"namespaces"`

	// List of non-critical errors, that occurred during resource retrieval.
	Errors []errors.StatusError `json:"errors,omitempty"`
}

// Namespace is a presentation layer view of Kubernetes namespaces. This means it is namespace plus
// additional augmented data we can get from other sources.
type Namespace struct {
	ObjectMeta        api.ObjectMeta                         `json:"objectMeta"`
	TypeMeta          api.TypeMeta                           `json:"typeMeta"`
	ResourceQuotaList *resourcequota.ResourceQuotaDetailList `json:"resourceQuotaList"`
	// Phase is the current lifecycle phase of the namespace.
	Phase v1.NamespacePhase `json:"phase"`
	Use   *NamespaceUse     `json:"use"`
}

type NamespaceUse struct {
	UseCPU     string `json:"useCPU"`
	UseMemory  string `json:"useMemory"`
	UseStorage string `json:"useStorage"`
}

type NamespaceUserRights struct {
	UserId   string `json:"userId" valid:"-"`
	UserName string `json:"userName" valid:"length(1|36)~用户名长度不能超过36"`
	Right    bool   `json:"right" valid:"-"`
	IsShared string `json:"isShared" valid:"-"`
}

type RemoveNamespaceUserRights struct {
	Item []NamespaceUserRights `json:"item" valid:"-"`
}

type PrometheusMetrics struct {
	Status string      `json:"status,omitempty" yaml:"status,omitempty"`
	Data   ClusterData `json:"data,omitempty" yaml:"data,omitempty"`
}

type ClusterData struct {
	ResultType string            `json:"resultType,omitempty" yaml:"resultType,omitempty"`
	Result     []NamespaceResult `json:"result,omitempty" yaml:"result,omitempty"`
}

type NamespaceResult struct {
	MetricData Metric        `json:"metric,omitempty" yaml:"metric,omitempty"`
	ValueData  []interface{} `json:"value,omitempty" yaml:"value,omitempty"`
}

type Metric struct {
	Namespace string `json:"namespace,omitempty" yaml:"namespace,omitempty"`
}

type EnvironmentList struct {
	Environments []*Environment `json:"environments"`
}

type Environment struct {
	Id          string `json:"id,omitempty"`
	Name        string `json:"name,omitempty"`
	DisplayName string `json:"displayName"`
	Status      string `json:"status,omitempty"`
	Eip         string `json:"eip,omitempty"`
	ExternalIp  string `json:"externalIp,omitempty"`
	UseIstio    bool   `json:"useIstio"`
	UseSlb      bool   `json:"useSlb"`
	IsShared    string `json:"isShared"`
}
